library(tidyverse)
library(sf) #for simple feature spatial data
library(mapview) #for interactive mapping
#devtools::install_github("thomasp85/gganimate")
library(gganimate) #for animations
library(knitr)
library(raster)
library(lubridate)
#load albatross data
albatross_sf <- read_tsv("data_files/Study2911040", comment="##", col_types = "Tnncc") %>% # Tnncc = time, number, number, character, character
as.data.frame() %>%
na.omit() %>%
st_as_sf(coords = c("location_long", "location_lat"), crs=4326)
#load zebra data
zebra_sf <- read_csv("data_files/Zebra.csv") %>%
dplyr::select(ID = Name, 4:6) %>%
mutate(timestamp = as.POSIXct(lubridate::mdy_hm(Date))) %>%
st_as_sf(., coords = 3:4, crs = "+init=epsg:4326") %>% #longlat
st_transform("+init=epsg:32733") #convert to UTM
## Warning: Missing column names filled in: 'X1' [1]
Let’s plot the albatross data.
# Create continental background
earth <- st_as_sf(rnaturalearth::countries110)
bbox <- st_bbox(albatross_sf, crs=st_crs(earth))
area <- st_crop(earth, bbox)
# Plot
albatross_sf %>%
ggplot() +
geom_sf(aes(colour = individual_id)) +
geom_sf(data = area, fill = 'gray') +
labs(title = 'Albatross tracks') +
theme_classic() +
theme(panel.background = element_rect(fill = 'lightblue'))
We will use the mapview package to make an interactive plot.
albatross_sf %>%
mapview(zcol="individual_id")